home *** CD-ROM | disk | FTP | other *** search
/ 17 Bit Software 6: Level 6 / 17 Bit - Level 6 (1998)(Epic Marketing)[!].iso / quartz / q0429.dms / q0429.adf / libshade / setup.c < prev    next >
C/C++ Source or Header  |  1992-05-20  |  6KB  |  262 lines

  1. /*
  2.  * setup.c
  3.  *
  4.  * Copyright (C) 1989, 1991, Craig E. Kolb
  5.  * All rights reserved.
  6.  *
  7.  * This software may be freely copied, modified, and redistributed
  8.  * provided that this copyright notice is preserved on all copies.
  9.  *
  10.  * You may not distribute this software, in whole or in part, as part of
  11.  * any commercial product without the express consent of the authors.
  12.  *
  13.  * There is no warranty or other guarantee of fitness of this software
  14.  * for any purpose.  It is provided solely "as is".
  15.  *
  16.  * $Id: setup.c,v 4.0.1.2 92/01/14 18:29:35 cek Exp Locker: cek $
  17.  *
  18.  * $Log:    setup.c,v $
  19.  * Revision 4.0.1.2  92/01/14  18:29:35  cek
  20.  * patch3: Added initialization of cpp option.
  21.  * 
  22.  * Revision 4.0.1.1  91/09/29  15:52:20  cek
  23.  * patch1: Added crop window initialization.
  24.  * patch1: Moved RSViewing call to appropriate location.
  25.  * 
  26.  * Revision 4.0  91/07/17  14:47:24  kolb
  27.  * Initial version.
  28.  * 
  29.  */
  30. #include "rayshade.h"
  31. #include "defaults.h"
  32. #include "libsurf/surface.h"
  33. #include "libsurf/atmosphere.h"
  34. #include "liblight/light.h"
  35. #include "liblight/infinite.h"
  36. #include "libobj/list.h"
  37. #include "options.h"
  38. #include "stats.h"
  39. #include "viewing.h"
  40. #include "picture.h"
  41.  
  42. #ifdef MULTIMAX
  43. #include <parallel.h>
  44. #define SHARED_BYTES    23    /* 2^23 bytes of shared memory */
  45. #endif
  46.  
  47. extern GeomList *Defstack;
  48.  
  49. static void SetupWorld();
  50.  
  51. /*
  52.  * Set default parameters
  53.  */
  54. void
  55. RSSetup()
  56. {
  57.     extern SurfList *CurSurf;
  58.     extern Medium TopMedium;
  59.     extern void NoiseInit();
  60. #ifdef MULTIMAX
  61.     unsigned int bytes;
  62.  
  63.     /*
  64.      * Initialize shared memory stuff.
  65.      */
  66.     bytes = 1 << SHARED_BYTES;
  67.     if (share_malloc_init(bytes) == -1) {
  68.         RLerror(RL_PANIC, "Cannot share_malloc %d bytes.\n",bytes);
  69.     } else
  70.         fprintf(fstats,"Malloced %d bytes of shared memory.\n",
  71.                 bytes);
  72. #endif
  73.  
  74.     Camera.hfov = HFOV;
  75.     Camera.vfov = UNSET;
  76.     Camera.pos.x = EYEX;
  77.     Camera.pos.y = EYEY;
  78.     Camera.pos.z = EYEZ;
  79.     Camera.lookp.x = LOOKX;
  80.     Camera.lookp.y = LOOKY;
  81.     Camera.lookp.z = LOOKZ;
  82.     Camera.up.x = UPX;
  83.     Camera.up.y = UPY;
  84.     Camera.up.z = UPZ;
  85.     Camera.focaldist = UNSET;
  86.     Camera.aperture = 0.;
  87.  
  88.     Screen.xres = Screen.yres = UNSET;
  89.  
  90.     Options.cpp = TRUE;
  91.     Options.maxdepth = MAXDEPTH;
  92.     Options.report_freq = REPORTFREQ;
  93.     Options.jitter = TRUE;
  94.     Options.samples = UNSET;
  95.     Options.gaussian = GAUSSIAN;
  96.     Options.filterwidth = UNSET;
  97.     Options.contrast.r = UNSET;
  98.     Options.ambient.r = Options.ambient.g =
  99.         Options.ambient.b = 1.0;
  100.     Options.cutoff.r = UNSET;
  101.     Options.cache = TRUE;
  102.     Options.shadowtransp = TRUE;
  103.     Options.crop[LOW][X] = Options.crop[LOW][Y] = 0.;
  104.     Options.crop[HIGH][X] = Options.crop[HIGH][Y] = 1.;
  105.     Stats.fstats = stderr;
  106.     Options.pictfile = stdout;
  107. #ifdef URT
  108.     Options.alpha = TRUE;
  109.     Options.exp_output = FALSE;
  110. #endif
  111.     Options.gamma = GAMMA;
  112.     Options.eyesep = UNSET;
  113. #ifdef LINDA
  114.     Options.workers = WORKERS;
  115. #endif
  116.  
  117.     Options.totalframes = 1;
  118.     Options.startframe = 0;
  119.     Options.starttime = 0.;
  120.     Options.framelength = 1.;
  121.     Options.shutterspeed = 0.;
  122.  
  123.     TopMedium.index = DEFAULT_INDEX;
  124.     TopMedium.statten = 1.0;
  125.     NoiseInit();            /* Initialize values for Noise() */
  126.  
  127.     /*
  128.      * Top of object definition stack points to the World object.
  129.      * The World object is always a list.
  130.      */
  131.     Defstack = GeomStackPush(GeomListCreate(), (GeomList *)NULL);
  132.     Defstack->obj->name = strsave("World");
  133.     /* Initialize surface stack */
  134.     CurSurf = SurfPush((Surface *)NULL, (SurfList *)NULL);
  135. }
  136.  
  137. /*
  138.  * cleanup()
  139.  *
  140.  * Initialize options/variables not set on command line or in input file.
  141.  * Perform sanity checks on widow dimension, maxdepth, etc.
  142.  */
  143. void
  144. RSCleanup()
  145. {
  146.     extern Light *Lights;
  147.     extern void OpenStatsFile();
  148.     extern FILE *yyin;
  149.  
  150.     yyin = (FILE *)NULL;    /* mark that we're done reading input */
  151.  
  152.     if (Options.samples == UNSET)
  153.         Options.samples = DEFSAMPLES;
  154.  
  155.     if (Options.filterwidth == UNSET) {
  156.         if (Options.gaussian)
  157.             Options.filterwidth = FILTERWIDTH;
  158.         else
  159.             /* Default box filter width of 1.0 */
  160.             Options.filterwidth = 1.0;
  161.     }
  162.  
  163.     Options.endframe = Options.startframe + Options.totalframes -1;
  164.  
  165.     OpenStatsFile();
  166.  
  167.     ViewingSetup();
  168.  
  169.     if (Options.cutoff.r == UNSET)
  170.         Options.cutoff.r = Options.cutoff.g =
  171.             Options.cutoff.b = DEFCUTOFF;
  172.  
  173.     /*
  174.      * Set contrast.
  175.      */
  176.     if (Options.contrast.r == UNSET) {
  177.         Options.contrast.r = DEFREDCONT;
  178.         Options.contrast.g = DEFGREENCONT;
  179.         Options.contrast.b = DEFBLUECONT;
  180.     }
  181.  
  182.     /*
  183.      * Image gamma is inverse of display gamma.
  184.      */
  185.     if (fabs(Options.gamma) > EPSILON)
  186.         Options.gamma = 1. / Options.gamma;
  187.     else
  188.         Options.gamma = FAR_AWAY;
  189.  
  190.     if (Options.maxdepth < 0)
  191.         Options.maxdepth = 0;
  192.  
  193.  
  194.     LightSetup();
  195. }
  196.  
  197. void
  198. RSStartFrame(frame)
  199. int frame;
  200. {
  201.     /*
  202.      * Set the frame start time
  203.      */
  204.     Options.framenum = frame;
  205.     Options.framestart = Options.starttime +
  206.             Options.framenum*Options.framelength;
  207.     SamplingSetTime(Options.framestart, Options.shutterspeed,
  208.             Options.framenum);
  209.     /*
  210.      * Set up viewing parameters.
  211.      * Can't animate camera yet; when possible, this will
  212.      * need to be much smarter.
  213.      * RSViewing();
  214.      */
  215.  
  216.     /*
  217.      * Initialize world
  218.      */
  219.     WorldSetup();
  220. }
  221.  
  222. /*
  223.  * Initialize non-time-varying goodies.
  224.  */
  225. void
  226. RSInitialize(argc, argv)
  227. int argc;
  228. char **argv;
  229. {
  230.     /*
  231.       * Initialize variables, etc.
  232.      */
  233.     RSSetup();
  234.     /*
  235.      * Parse options from command line.
  236.      */
  237.     RSOptionsSet(argc, argv);
  238.     /*
  239.      * Process input file.
  240.      */
  241.     if (Options.verbose) {
  242.         VersionPrint();
  243.         fprintf(Stats.fstats,"Reading input file...\n");
  244.         (void)fflush(Stats.fstats);
  245.     }
  246.     RSReadInputFile();
  247.     /*
  248.      * Set variables that weren't set on command line
  249.      * or in input file.
  250.      */
  251.     RSCleanup();
  252.     /*
  253.      * Set sampling options.
  254.      */
  255.     SamplingSetOptions(Options.samples, Options.gaussian,
  256.                Options.filterwidth);
  257.     /*
  258.      * Camera is currently static; initialize it here.
  259.      */
  260.     RSViewing();
  261. }
  262.